<template>
  <div>
    <dt-modal-info ref='modal' title='房源明细' :line-number='4' :label-width='120' :width='1200' @close='onClose'>
      <div slot='bottom' style="padding: 0 20px 50px 20px;">
        <div class="flex" style="margin-bottom: 20px;">
          <div class="flex-1">
          </div>
          <div v-if="info.bonusType == 'STANDARD'">
            ！调整金额将影响房源年底及交房奖金计算，请注意填写
          </div>
        </div>
        <dt-grid height-resize ref='person' :list='info.bonusPersonDetails' :row-style="rowStyle"
          empty-text="该房源下无可发放奖金人员，请检查奖金模板及团队配置">
        </dt-grid>
      </div>
    </dt-modal-info>
    <reason-modal ref='reason'></reason-modal>
  </div>

</template>

<script>
  import Opt from '../opt/RoomOpt.js'
  import Column from '../opt/RoomPersonColumn.js'
  
  import reasonModal from './reason-modal.vue'
  
  import billMgr from '@/biz/bonus/bill'

  export default {
    components: {
      reasonModal
    },
    data() {
      return {
        info: {},
        isEdit: false
      }
    },
    mounted() {
      
    },
    methods: {
      rowStyle(e) {
        return {
          'background-color': e.row.isCanAdjust != false ? '#fff' : '#F2F2F2'
        }
      },
      show(info) {
        this.isEdit = false
        this.info = info
        this.$refs.modal.show(new Opt(info, this.info.bonusType))
        this.init()
      },
      init() {
        let change = (item) => {
          let update = () => {
            this.isEdit = true
            if (item.adjustBonus == null) {
              item.adjustBonus = 0
            }
            billMgr.roomPersonEdit(this.$route.query.id, item.bonusDetailId, item.adjustBonus, item.adjustReason).then(res => {
              item.shouldBonusAmount = item.bonusAmount + item.adjustBonus
              item.bonusPool = item.shouldBonusAmount * (item.bonusPoolRadio || 0)
              item.actualBonusAmount = item.shouldBonusAmount - item.bonusPool
            })
          }
          if (Number(item.adjustBonus) != 0) {
            if (!item.adjustReason || item.adjustReason.length == 0) {
              this.$refs.reason.show((reason) => {
                if (reason) {
                  item.adjustReason = reason
                } else {
                  item.adjustBonus = 0
                }
                update()
              })
              return
            }
          }
          update()
        }
        this.$refs.person.init(this, new Column(this.$route.name, this.info.bonusType, this.info.isParticipate, change))
      },
      hide() {
        this.$refs.modal.hide()
      },
      onClose() {
        if (this.isEdit) {
          this.$emit('update')
        }
      },
    }
  }
</script>

<style>
  .cc{
    background-color: #9EA7B4;
  }
</style>
